home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 3 / CD ACTUAL 3.iso / linux / incoming / jstools-.6v3 / jstools- / jstools-tk3.6v3.0 / lib / jeditmodes / jdoc-mode.tcl < prev    next >
Encoding:
Text File  |  1995-02-09  |  8.3 KB  |  302 lines

  1. # jdoc-mode.tcl - mode for rich-text hypertext documents
  2. ######################################################################
  3.  
  4. proc mode:jdoc:init { t } {
  5.   global JEDIT_MODEPREFS
  6.   
  7.   j:read_prefs -array JEDIT_MODEPREFS -prefix jdoc \
  8.     -directory ~/.tk/jeditmodes -file jdoc-defaults {
  9.     {textfont default}
  10.     {textwidth 80}
  11.     {textheight 24}
  12.     {textwrap word}
  13.     {sabbrev 0}
  14.     {dabbrev 0}
  15.     {autobreak 0}
  16.     {autoindent 0}
  17.     {savestate 0}
  18.     {buttonbar 1}
  19.     {menu,editor 1}
  20.     {menu,file 1}
  21.     {menu,edit 1}
  22.     {menu,prefs 0}
  23.     {menu,abbrev 1}
  24.     {menu,filter 1}
  25.     {menu,format 1}
  26.     {menu,display 1}
  27.     {menu,mode1 1}
  28.     {menu,mode2 1}
  29.     {menu,user 1}
  30.   }
  31.  
  32.   $t tag bind jdoc:xref:link <Control-ButtonRelease-1> \
  33.     {jdoc:x_link %W %x %y}
  34.   $t tag bind jdoc:xref:manpage <Control-ButtonRelease-1> \
  35.     {jdoc:x_manpage %W %x %y}
  36.   $t tag configure jdoc:xref:link -underline 1
  37.   $t tag configure jdoc:xref:manpage -underline 1
  38.   
  39.   # not marked in jdoc, but marked here so you get visual feedback
  40.   # when you create it:
  41.   $t tag configure jdoc:anchor:anchorname -background grey75 -bgstipple gray25
  42.   
  43.   #
  44.   # OBSOLETE:
  45.   #
  46.   $t tag configure jdoc:xref:topic -underline 1 \
  47.     -background grey75 -borderwidth 1 -relief raised
  48.   $t tag configure jdoc:xref:section -underline 1 \
  49.     -background grey75 -borderwidth 1 -relief raised
  50. }
  51.  
  52. ######################################################################
  53. # save entire contents of text widget, including tags and marks
  54. #   (overrides normal write procedure)
  55. ######################################################################
  56.  
  57. proc mode:jdoc:write { filename t } {
  58.   j:tag:archive_text_widget $t $filename
  59. }
  60.  
  61. ######################################################################
  62. # read in archive of text widget, including tags and marks
  63. #   (overrides normal read procedure)
  64. ######################################################################
  65.  
  66. proc mode:jdoc:read { filename t } {
  67.   jedit:font:roman $t                ;# start tagging as roman
  68.   if { ! [file exists $filename] } then {
  69.     $t delete 1.0 end
  70.     $t mark set insert 1.0
  71.     jedit:set_label $t "$filename (new file)"
  72.   } else {                    ;# file exists
  73.     j:tag:restore_text_widget $t $filename
  74.     global JEDIT_MODEPREFS
  75.     if { ! $JEDIT_MODEPREFS(jdoc,savestate) } {
  76.       $t tag remove sel 1.0 end
  77.       $t mark set insert 1.0
  78.       $t yview 1.0
  79.     }
  80.   }
  81. }
  82.  
  83. ######################################################################
  84. # show tags at insert point (useful for seeing anchor names, etc.)
  85. ######################################################################
  86. ### THIS SHOULD BE ADDED TO BASE JEDIT FUNCTIONALITY
  87.  
  88. proc mode:jdoc:show_tags { t } {
  89.   set tags [$t tag names insert]
  90.   j:more -title "Current Tags" -width 40 -height 10 \
  91.     -text [join [lsort $tags] "\n"]
  92. }
  93.  
  94. ######################################################################
  95.  
  96. proc mode:jdoc:mkx_anchor { t } {
  97.   set from [$t index sel.first]
  98.   set to [$t index sel.last]
  99.   set anchor [string trim [$t get $from $to]]
  100.   regsub -all -- {[ +-]} $anchor {_} anchor
  101.   set anchor [j:prompt -title "Anchor Name" -text "Anchor name:" \
  102.     -default $anchor]
  103.   
  104.   if {"x$anchor" == "x"} {
  105.     return 1
  106.   }
  107.   
  108.   foreach tag [list \
  109.     jdoc:anchor:anchorname \
  110.     jdoc:anchorname:$anchor \
  111.   ] {
  112.     j:tag:tag_text $t $tag $from $to
  113.   }
  114.   return 0
  115. }
  116.  
  117. proc mode:jdoc:mkx_link { t } {
  118.   set from [$t index sel.first]
  119.   set to [$t index sel.last]
  120.   set link "[string trim [$t get $from $to]].jdoc"
  121.   regsub -all -- {[ +-]} $link {_} link
  122.   set link [j:prompt -file 1 -title "Link Name" -text "Link to:" \
  123.     -default $link -file 1]
  124.   
  125.   if {"x$link" == "x"} {
  126.     return 1
  127.   }
  128.   
  129.   foreach tag [list \
  130.     jdoc:xref:link \
  131.     jdoc:link:$link \
  132.   ] {
  133.     j:tag:tag_text $t $tag $from $to
  134.   }
  135.   return 0
  136. }
  137.  
  138. proc mode:jdoc:mkx_anchor_link { t } {
  139.   set from [$t index sel.first]
  140.   set to [$t index sel.last]
  141.   set link "#[string trim [$t get $from $to]]"
  142.   regsub -all -- {[ +-]} $link {_} link
  143.   set link [j:prompt -title "Link Name" -text "Link to:" \
  144.     -default $link -file 1]
  145.   
  146.   if {"x$link" == "x"} {
  147.     return 1
  148.   }
  149.   
  150.   foreach tag [list \
  151.     jdoc:xref:link \
  152.     jdoc:link:$link \
  153.   ] {
  154.     j:tag:tag_text $t $tag $from $to
  155.   }
  156.   return 0
  157. }
  158.  
  159. ### proc mode:jdoc:mkx_topic { t } {
  160. ###   set from [$t index sel.first]
  161. ###   set to [$t index sel.last]
  162. ###   set topic [$t get $from $to]
  163. ###   
  164. ###   foreach tag [list \
  165. ###     jdoc:xref:topic \
  166. ###     jdoc:topic:$topic \
  167. ###     richtext:font:bold \
  168. ###   ] {
  169. ###     j:tag:tag_text $t $tag $from $to
  170. ###   }
  171. ### }
  172. ### 
  173. ### proc mode:jdoc:mkx_section { t } {
  174. ###   set from [$t index sel.first]
  175. ###   set to [$t index sel.last]
  176. ###   set section [$t get $from $to]
  177. ###   
  178. ###   foreach tag [list \
  179. ###     jdoc:xref:section \
  180. ###     jdoc:section:$section \
  181. ###     richtext:font:bolditalic \
  182. ###   ] {
  183. ###     j:tag:tag_text $t $tag $from $to
  184. ###   }
  185. ### }
  186.  
  187. proc mode:jdoc:mkx_manpage { t } {
  188.   set from [$t index sel.first]
  189.   set to [$t index sel.last]
  190.   set manpage [string trim [$t get $from $to]]
  191.   set manpage [j:prompt -title "Link Name" -text "Manual page:" \
  192.     -default $manpage]
  193.   
  194.   if {"x$manpage" == "x"} {
  195.     return 1
  196.   }
  197.   
  198.   foreach tag [list \
  199.     jdoc:xref:manpage \
  200.     jdoc:manpage:$manpage \
  201.     richtext:font:typewriter \
  202.   ] {
  203.     j:tag:tag_text $t $tag $from $to
  204.   }
  205.   return 0
  206. }
  207.  
  208. ######################################################################
  209. # mode:jdoc:mksectionsmenu menu t - find all level 1 headings in text
  210. ######################################################################
  211.  
  212. proc mode:jdoc:mksectionsmenu { menu t } {
  213.   set ranges [$t tag ranges richtext:font:heading1]
  214.   set sections {}
  215.   
  216.   ;# step through ranges two-at-a-time (start and end)
  217.   while { [llength $ranges] > 0 } {
  218.     set start [lindex $ranges 0]
  219.     set end [lindex $ranges 1]
  220.     set ranges [lreplace $ranges 0 1]    ;# with nothing, ie shift
  221.     set section_name [string trim [$t get $start $end]]
  222.     set section_name [lindex [split $section_name "\n"] 0]
  223.     lappend sections [list $section_name $start]
  224.   }
  225.   
  226.   $menu delete 0 last
  227.   
  228.   $menu add command -label "Top" -command \
  229.     "$t mark set insert 1.0; $t yview -pickplace insert"
  230.   $menu add separator
  231.   foreach pair $sections {
  232.     set section [lindex $pair 0]
  233.     set location [lindex $pair 1]
  234.     $menu add command -label $section \
  235.       -command "$t mark set insert $location; $t yview insert"
  236.   }
  237.   $menu add separator
  238.   $menu add command -label "Bottom" -command \
  239.     "$t mark set insert end; $t yview -pickplace insert"
  240. }
  241.  
  242. ######################################################################
  243.  
  244. proc mode:jdoc:mkmenu1 { menu t } {
  245.   menubutton $menu -text {jdoc} -menu $menu.m
  246.   
  247.   menu $menu.m
  248.   $menu.m add command -label {Make Section Title} \
  249.     -accelerator {[1]} \
  250.     -command "jedit:font:heading1 $t"
  251.   $menu.m add command -label {Make Subsection Heading} \
  252.     -accelerator {[2]} \
  253.     -command "jedit:font:heading2 $t"
  254.   $menu.m add command -label {Make Subsubsection Heading} \
  255.     -accelerator {[3]} \
  256.     -command "jedit:font:heading2 $t"
  257.   $menu.m add command -label {Make Overall Topic Title} \
  258.     -command "jedit:font:heading0 $t"
  259.   $menu.m add separator
  260.   $menu.m add command -label {Show Tags at Insert . . .} \
  261.     -accelerator {[5]} \
  262.     -command "
  263.       mode:jdoc:show_tags $t
  264.     "
  265.   $menu.m add separator
  266.   $menu.m add command -label {Anchor Name . . .} \
  267.     -accelerator {[6]} \
  268.     -command "
  269.       mode:jdoc:mkx_anchor $t
  270.     "
  271.   $menu.m add command -label {Local Cross Reference . . .} \
  272.     -accelerator {[7]} \
  273.     -command "
  274.       mode:jdoc:mkx_anchor_link $t
  275.     "
  276.   $menu.m add command -label {Cross Reference . . .} \
  277.     -accelerator {[8]} \
  278.     -command "
  279.       mode:jdoc:mkx_link $t
  280.     "
  281.   $menu.m add command -label {Man Page Reference . . .} \
  282.     -accelerator {[9]} \
  283.     -command "
  284.       mode:jdoc:mkx_manpage $t
  285.     "
  286.   
  287.   bind $t <Meta-Key-1> "jedit:font:heading1 $t"
  288.   bind $t <Meta-Key-2> "jedit:font:heading2 $t"
  289.   bind $t <Meta-Key-3> "jedit:font:heading3 $t"
  290.   bind $t <Meta-Key-5> "mode:jdoc:show_tags $t"
  291.   bind $t <Meta-Key-6> "mode:jdoc:mkx_anchor $t"
  292.   bind $t <Meta-Key-7> "mode:jdoc:mkx_anchor_link $t"
  293.   bind $t <Meta-Key-8> "mode:jdoc:mkx_link $t"
  294.   bind $t <Meta-Key-9> "mode:jdoc:mkx_manpage $t"
  295. }
  296.  
  297. proc mode:jdoc:mkmenu2 { menu t } {
  298.   menubutton $menu -text {Sections} -menu $menu.m
  299.   
  300.   menu $menu.m -postcommand "mode:jdoc:mksectionsmenu $menu.m $t"
  301. }
  302.